package com.ht.serviceimpl;

import java.util.List;


import com.ht.dao.PersonDao;
import com.ht.model.Person;
import com.ht.service.PersonService;
import com.ht.util.Constants;
import com.ht.util.MyPage;

public class PersonServiceImpl implements PersonService {

	PersonDao personDao ;
	
	public PersonDao getPersonDao() {
		return personDao;
	}

	public void setPersonDao(PersonDao personDao) {
		this.personDao = personDao;
	}

	public int addPerson(Person  person ){
		int result =0  ;
		Person sa = personDao.getPersonById(person);
		if (sa == null) {
		    result = personDao.insertPerson(person);
		} else {
			result = 2;
		}
		return result;
	}
		
	public int deletePerson(Person  person) {
		return personDao.deletePerson(person);
	}

	public int updatePerson(Person  person) {
		return personDao.updatePerson(person);
	}
		
	public Person getPersonByName(String name ){
		return personDao.getPersonByName(name);
	}
	
	public Person getPersonByDept(String dept ){
		return personDao.getPersonByDept(dept);
	}

	public Person getPersonById(Person  person) {
		return personDao.getPersonById(person);
	}
		
	public MyPage selectByCon(Person person, int curPage){
		MyPage page = new MyPage();
		List result = personDao.selectByCon(person,curPage,Constants.PAGE_SIZE) ;
		int recordCount = personDao.getRecordCount(person);
		int totalPage = (recordCount%Constants.PAGE_SIZE==0)?recordCount/Constants.PAGE_SIZE:recordCount/Constants.PAGE_SIZE+1;
		page.setResult(result);
		page.setCurPage(curPage);
		page.setRecordCount(recordCount);
		page.setTotalPage(totalPage);
		return page ;
	  }
	
		
		

}
